package com.flx.multi.thread.juc.countdown;

import java.util.concurrent.CountDownLatch;

/**
 * @Author Fenglixiong
 * @Create 2021/11/17 17:23
 * @Description
 **/
public class CountDownLatchMain {

    public static void main(String[] args) throws InterruptedException {

        CountDownLatch latch = new CountDownLatch(2);

        new Thread(()->{
            try {
                System.out.println("ThreadA start...");
                Thread.sleep(2000);
                System.out.println("ThreadA end...");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                latch.countDown();
            }
        }).start();

        new Thread(()->{
            try {
                System.out.println("ThreadB start...");
                Thread.sleep(5000);
                System.out.println("ThreadB end...");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }finally {
                latch.countDown();
            }
        }).start();

        latch.await();

        System.out.println("main end !");

    }

}
